#/bin/bash

#echo ${HOME}
#echo $(ps -u $(basename ${HOME}) | grep redis)

declare -i i=0
declare -i j=0
pid=""
pname=""
#grepvar=$1
grepvar="serverMain"


for var in $(ps -u $(basename $HOME) | grep $grepvar)
do 
  #修改为整数运算 (())或者 []
  #declare -i b=$i%4
  if [ $((i%4)) -eq 0 ]; then 
    pid=$var
  fi 
  #declare -i a=$((i+1))%4
  if [ $((((i+1))%4)) -eq 0 ]; then 
    pname=$var
  fi 

  if [ "$pid" != "" ] && [ "$pname" != "" ];
  then 
    #echo $pid $pname
    #if kill -9 $pid then ... fi
    kill -9 $pid 
    if [ $? -eq 0 ]
    then 
      echo "$pname stoped"
    else
      echo "$pname can not stop"

    fi 
  fi  


  i+=1 
  #echo $pid $pname
done 

./serverMain
